home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / php / PEAR / Log / display.php < prev    next >
Encoding:
PHP Script  |  2007-12-20  |  3.9 KB  |  142 lines

  1. <?php
  2. /**
  3.  * $Header: /repository/pear/Log/Log/display.php,v 1.9 2006/06/29 07:09:21 jon Exp $
  4.  *
  5.  * @version $Revision: 1.9 $
  6.  * @package Log
  7.  */
  8.  
  9. /**
  10.  * The Log_display class is a concrete implementation of the Log::
  11.  * abstract class which writes message into browser in usual PHP maner.
  12.  * This may be useful because when you use PEAR::setErrorHandling in
  13.  * PEAR_ERROR_CALLBACK mode error messages are not displayed by
  14.  * PHP error handler.
  15.  *
  16.  * @author  Paul Yanchenko <pusher@inaco.ru>
  17.  * @since   Log 1.8.0
  18.  * @package Log
  19.  *
  20.  * @example display.php     Using the display handler.
  21.  */
  22. class Log_display extends Log
  23. {
  24.     /**
  25.      * String to output before an error message
  26.      * @var string
  27.      * @access private
  28.      */
  29.     var $_error_prepend = '';
  30.  
  31.     /**
  32.      * String to output after an error message
  33.      * @var string
  34.      * @access private
  35.      */
  36.     var $_error_append = '';
  37.  
  38.     /**
  39.      * String used to represent a line break.
  40.      * @var string
  41.      * @access private
  42.      */
  43.     var $_linebreak = "<br />\n";
  44.  
  45.     /**
  46.      * Constructs a new Log_display object.
  47.      *
  48.      * @param string $name     Ignored.
  49.      * @param string $ident    The identity string.
  50.      * @param array  $conf     The configuration array.
  51.      * @param int    $level    Log messages up to and including this level.
  52.      * @access public
  53.      */
  54.     function Log_display($name = '', $ident = '', $conf = array(),
  55.                          $level = PEAR_LOG_DEBUG)
  56.     {
  57.         $this->_id = md5(microtime());
  58.         $this->_ident = $ident;
  59.         $this->_mask = Log::UPTO($level);
  60.  
  61.         if (isset($conf['error_prepend'])) {
  62.             $this->_error_prepend = $conf['error_prepend'];
  63.         } else {
  64.             $this->_error_prepend = ini_get('error_prepend_string');
  65.         }
  66.  
  67.         if (isset($conf['error_append'])) {
  68.             $this->_error_append = $conf['error_append'];
  69.         } else {
  70.             $this->_error_append = ini_get('error_append_string');
  71.         }
  72.  
  73.         if (isset($conf['linebreak'])) {
  74.             $this->_linebreak = $conf['linebreak'];
  75.         }
  76.     }
  77.  
  78.     /**
  79.      * Opens the display handler.
  80.      *
  81.      * @access  public
  82.      * @since   Log 1.9.6
  83.      */
  84.     function open()
  85.     {
  86.         $this->_opened = true;
  87.         return true;
  88.     }
  89.  
  90.     /**
  91.      * Closes the display handler.
  92.      *
  93.      * @access  public
  94.      * @since   Log 1.9.6
  95.      */
  96.     function close()
  97.     {
  98.         $this->_opened = false;
  99.         return true;
  100.     }
  101.  
  102.     /**
  103.      * Writes $message to the text browser. Also, passes the message
  104.      * along to any Log_observer instances that are observing this Log.
  105.      *
  106.      * @param mixed  $message    String or object containing the message to log.
  107.      * @param string $priority The priority of the message.  Valid
  108.      *                  values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
  109.      *                  PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
  110.      *                  PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
  111.      * @return boolean  True on success or false on failure.
  112.      * @access public
  113.      */
  114.     function log($message, $priority = null)
  115.     {
  116.         /* If a priority hasn't been specified, use the default value. */
  117.         if ($priority === null) {
  118.             $priority = $this->_priority;
  119.         }
  120.  
  121.         /* Abort early if the priority is above the maximum logging level. */
  122.         if (!$this->_isMasked($priority)) {
  123.             return false;
  124.         }
  125.  
  126.         /* Extract the string representation of the message. */
  127.         $message = $this->_extractMessage($message);
  128.  
  129.         /* Build and output the complete log line. */
  130.         echo $this->_error_prepend .
  131.              '<b>' . ucfirst($this->priorityToString($priority)) . '</b>: '.
  132.              nl2br(htmlspecialchars($message)) .
  133.              $this->_error_append . $this->_linebreak;
  134.  
  135.         /* Notify observers about this log message. */
  136.         $this->_announce(array('priority' => $priority, 'message' => $message));
  137.  
  138.         return true;
  139.     }
  140.  
  141. }
  142.